<?php
	header('content-type:text/html;charset="utf-8"');//设置字符编码
	$con = mysql_connect("localhost","root","123456");
	if(isset($_POST['username']) || isset($_POST['submit'])){
		$username=@$_POST['username'];
	}else{
		exit('非法操作');
	}
	mysql_select_db("leshi", $con);
	
	$query="select * from user where user='$username'";
	$result=mysql_query($query);
	
	if(mysql_fetch_array($result)){
		echo true;
	}else{
		echo false;
	}
	
	if(isset($_POST['submit']) && $_POST['submit']=="注册"){
		$user=$_POST['username'];//username：表单的名称
		$pass=md5($_POST['password']);
		$sql="INSERT INTO user (id,user, password) VALUES (NULL,'$user','$pass')";
		mysql_query($sql);
		header('location:../login.html');
	}
	/*if (!mysql_query($query,$con))
	  {
	  die('Error:'.mysql_error());
	  }*/
	
	mysql_close($con);
	
?>